var express = require('express')
var router = express.Router()

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource')
})

router.post('/', (req, res) => {
  const { username } = req.body
  req.session.username = username
  res.json({
    code: 200,
    data: {
      message: 'success',
      username,
    }
  })
})

router.put('/', (req, res) => {
  const {username} = req.body
  if (username === req.session.username) {
    res.json({
      code: 200,
      data: {
        message: 'same',
      }
    })
  } else {
    res.json({
      code: 400,
      data: {
        message: 'not exist',
      }
    })
  }
})

module.exports = router
